package com.xuanwu.mall.file.ceph;

import org.javaswift.joss.model.Container;
import org.javaswift.joss.model.StoredObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * xuanwu-mall
 * com.xuanwu.mall.file.ceph
 *
 * @Description:
 * @Author：xuanwudeshuijngye_26567
 * @Date 2024-03-17 19:05
 * @Company: 旋舞科技有限公司
 **/
@Component
public class FileHandler {

    @Autowired
    private Container container;


    /****
     * 文件上传
     */
    public void upload(String fileName,byte[] bytes){
        // 获取容器
       StoredObject storedObject = container.getObject(fileName);
       //  文件上传
        storedObject.uploadObject(bytes);

    }


    /****
     * 文件下载
     */
    public byte[] download(String fileName){
        // 获取容器
        StoredObject storedObject = container.getObject(fileName);
        // 下载
        byte[] bytes = storedObject.downloadObject();

        return  bytes;
    }

}
